﻿using System;
using System.Configuration;

namespace Sustainalytics.Companies.Service
{
    public static class HostConfig
    {
        public static string GetHostUrl()
        {
            string url = ConfigurationManager.AppSettings["httpHostUrl"];
            bool useHttps;

            bool.TryParse(ConfigurationManager.AppSettings["UseHttps"], out useHttps);

            if (useHttps)
            {
                var uriBuilder = new UriBuilder(url);
                uriBuilder.Scheme = Uri.UriSchemeHttps;
                uriBuilder.Port = Int32.Parse(ConfigurationManager.AppSettings["httpsPort"]);
                url = uriBuilder.Uri.ToString();
            }

            return url;
        }
    }
}
